<template>
  <div class="net-container">
    <el-card class="net-card">
      <div class="title">
        <span class="desc">网络缴费</span>
        <img class="icon" src="@/assets/img/item-img/net.png" alt="" />
      </div>
      <div class="body">
        <div class="common-info">
          <el-tag type="info">基本信息</el-tag>
          <el-input class="disable-input" placeholder="姓名" disabled v-model="name">
            <template slot="prepend">姓名</template>
          </el-input>
          <el-input class="disable-input" placeholder="性别" disabled v-model="sex">
            <template slot="prepend">性别</template>
          </el-input>

          <el-input class="disable-input" placeholder="学号" disabled v-model="studentNum">
            <template slot="prepend">校号</template>
          </el-input>
          <el-input class="disable-input" placeholder="院系" disabled v-model="department">
            <template slot="prepend">院系</template>
          </el-input>
          <!-- class此处有冲突，蒋class改为了classes -->
          <el-input class="disable-input" placeholder="班级" disabled v-model="classes">
            <template slot="prepend">班级</template>
          </el-input>

          <el-input class="disable-input" placeholder="宿舍号" disabled v-model="dormitoryNum">
            <template slot="prepend">宿舍号</template>
          </el-input>
        </div>
        <div class="chargeInfo">
          <div class="title">充值信息</div>
          <div class="charge-desc">
            <div class="select-room">
              <el-select v-model="value" placeholder="请选择充值房间">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </div>
            <div class="money">
              <el-tag type="info">请输入充值金额</el-tag>
              <el-input-number v-model="amount" @change="handleChange" :min="0" label="充值金额"></el-input-number>
            </div>
          </div>
        </div>
        <div class="btn-container">
          <el-button type="primary" @click="commitAmount()">提交金额</el-button>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import commonServe from '../../api/service/common.serve'
export default {
  data() {
    return {
      id: window.sessionStorage.getItem('studentId'),
      name: '',
      sex: '',
      studentNum: '',
      department: '',
      classes: '',
      dormitoryNum: '',
      value: '', //房间
      options: [
        {
          value: 'g1-101', //真实值，用于传递参数
          label: 'g1-101' //选项展示的值
        },
        {
          value: 'g2-101',
          label: 'g2-101'
        },
        {
          value: 'g3-101',
          label: 'g3-101'
        },
        {
          value: 'g4-101',
          label: 'g4-101'
        },
        {
          value: 'b6-101',
          label: 'b6-101'
        }
      ],
      amount: '' //金额
    }
  },
  created() {
    this.getStudentInfo()
  },
  methods: {
    handleChange(val) {
      // console.log(e)
      this.amount = val
    },
    // 获取用户信息
    getStudentInfo() {
      commonServe
        .getStudentInfo(this.id)
        .then((res) => {
          // console.log(res)
          if (res.code === 200) {
            let obj = res.data.item
            this.name = obj.studentName
            this.studentNum = obj.studentNum
            this.sex = obj.sex
            this.department = obj.department
            this.classes = obj.classes
            this.dormitoryNum = obj.dormitoryNum
          } else {
            this.$message.warning('获取学生信息失败')
          }
        })
        .catch((err) => {
          this.$message('获取学生信息失败' || err.message)
        })
    },
    commitAmount() {
      if (!this.amount) {
        this.$message.warning('充值金额不能为0，请重新输入')
        return
      } else {
        //充值
        commonServe
          .chargeNetOrWater(this.id, this.amount, this.value)
          .then((res) => {
            // console.log(res)
            if (res.code === 200) {
              this.$message.success('充值成功')
            } else {
              this.$message.warning('没有查询到卡信息，请确保一卡通处于正常状态')
            }
          })
          .catch((err) => {
            this.$message.warning('充值失败，请刷新重试' || err.message)
          })
      }
    }
  }
}
</script>

<style lang="less" scoped>
.net-container {
  .net-card {
    .title {
      display: flex;
      align-items: center;
      .desc {
        font-size: 30px;
        color: #3a62d7;
        letter-spacing: 10px;
        font-weight: bold;
        text-shadow: 2px 2px 5px #999;
      }
      .icon {
        width: 40px;
        height: 40px;
      }
      .icon:hover {
        transform: translateY(-5px);
        transition: 0.5s;
      }
    }
    .body {
      padding: 50px 200px 0 200px;
      .common-info {
        .el-tag {
          margin-bottom: -10px;
        }
        .disable-input {
          margin-top: 20px;
        }
        .el-input.is-disabled /deep/ .el-input__inner {
          color: #606266;
        }
      }
      .chargeInfo {
        padding-top: 50px;
        .title {
          width: 100%;
          //   border-bottom: 1px solid #999;
          color: #999;
        }
        .charge-desc {
          padding-top: 20px;
          //   display: flex;
          //   align-items: center;
          //   justify-content: space-between;
          .select-room {
            .el-select {
              width: 100%;
            }
          }
          .select-room,
          .money {
            display: flex;
            align-items: center;
            justify-content: space-between;
          }
          .money {
            padding-top: 20px;
          }
        }
      }
      .btn-container {
        padding-top: 20px;
        .el-button {
          width: 100%;
          color: #fff;
        }
      }
    }
  }
}
</style>
